package com.apotik.legenda.panel;

import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JButton;
import javax.swing.JSeparator;
import javax.swing.JTable;
import javax.swing.KeyStroke;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.BorderLayout;
import java.awt.GridLayout;

import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.TableCellRenderer;

import com.apotik.legenda.bean.TrxUniqueNumberBean;
import com.apotik.legenda.custom.TableModelCustom;
import com.apotik.legenda.dao.SalesTrxDao;
import com.apotik.legenda.dao.SalesTrxObatDao;
import com.apotik.legenda.dao.TransactionUniqueNumberDao;
import com.apotik.legenda.dialog.AddDokterToTrxDialog;
import com.apotik.legenda.dialog.AddProductToTrxDialog;
import com.apotik.legenda.dialog.BayarDialog;
import com.apotik.legenda.dialog.EditTrxObatDiscountDialog;
import com.apotik.legenda.dialog.EditTrxObatQuantityDialog;
import com.apotik.legenda.dialog.EditTrxObatScDialog;
import com.apotik.legenda.dialog.InputPatientDialog;
import com.apotik.legenda.model.Doctor;
import com.apotik.legenda.model.Patients;
import com.apotik.legenda.model.Product;
import com.apotik.legenda.model.SalesTrx;
import com.apotik.legenda.model.SalesTrxObat;
import com.apotik.legenda.model.Shift;
import com.apotik.legenda.model.TransactionUniqueNumber;
import com.apotik.legenda.model.User;
import com.apotik.legenda.observer.PosObserver;
import com.apotik.legenda.util.AppUtil;
import com.apotik.legenda.util.CalendarUtil;

import java.awt.Font;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyListener;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;
import java.awt.event.KeyEvent;

import javax.swing.JTextField;
import javax.swing.border.LineBorder;

import java.awt.FlowLayout;

import javax.swing.border.MatteBorder;
import javax.swing.border.TitledBorder;


public class PosPanel extends JPanel implements ActionListener, PosObserver, FocusListener, KeyListener {
	private static final long serialVersionUID = 1L;
	
	public static final int UPDATE_QUANTITY = 101;
	public static final int UPDATE_DISCOUNT = 102;
	public static final int UPDATE_SC 		= 103;
	private User selectedCashier;
	private Shift shift;
	private SalesTrx currentSalesTrx;
	private Patients currentPatient;
	private int modelRow  = -1;
	
	
	private JSplitPane splitPane;
	
	private JLabel lblNoNotaValue;
	private JLabel lblTotal;
	
	private JButton btnTrxNew;
	private JButton btnBayar;
	private JButton btnBatal;
	private JButton btnAddProd;
	private JButton btnEditQuantity;
	private JButton btnEditDiscount;
	private JButton btnEditSc;
	private JButton btnHapusProd;
	private JButton btnCust;
	private JButton btnDokter;	
	
	private JTextField textFieldRU;
	private JTextField textFieldTotalObat;
	private JTextField textFieldUpAsrPersen;
	private JTextField textFieldUpAsrRp;
	private JTextField textFieldDiscountPersen;
	private JTextField textFieldDiscountRp;
	private JTextField textFieldBiayaDokter;
	private JTextField textFieldBiayaTindakan;
	private JTextField textFieldBiayaLab;
	private JTextField textFieldBiayaAdm;
	private JTextField textFieldMisc;
	private JTextField textFieldSubTotal;
	private JTextField textFieldCustNama;
	private JTextField textFieldCustAtasNama;
	private JTextField textFieldDokter;
	
	private JTable table;
	private TableModelCustom tableModel;
	private AddProductToTrxDialog addProductToTrxDialog;
	private EditTrxObatQuantityDialog editTrxObatQuantityDialog;
	private EditTrxObatDiscountDialog editTrxObatDiscountDialog;
	private EditTrxObatScDialog editTrxObatScDialog;
	private InputPatientDialog inputPatientDialog;
	private AddDokterToTrxDialog addDokterDialog;
	private BayarDialog bayarDialog;
	
	@SuppressWarnings("rawtypes")
	private JComboBox comboBoxTrxType;
	
	public PosPanel(User selectedCashier, Shift shift) {
		this.selectedCashier = selectedCashier;
		this.shift = shift;
		
		JPanel leftComp = leftComponents();
		JPanel rightComp = rightComponents();
		
		firstConditionForComp();
		
		splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftComp, rightComp);
		splitPane.setOneTouchExpandable(true);
		splitPane.setDividerLocation(180);
	}
	
	private JPanel leftComponents(){
		JPanel panel = new JPanel();
		panel.setLayout(null);
		
		String timeStart = CalendarUtil.dateToString_HHMM(shift.getStartTime());
		String timeFinish = CalendarUtil.dateToString_HHMM(shift.getFinishTime());
		
		String kasirValue = selectedCashier.getFullName();
		String shiftValue = shift.getShiftName()+" ("+timeStart+" - "+timeFinish+")";
		
		btnTrxNew = new JButton("Transaksi Baru");
		panel.add(btnTrxNew);
		btnTrxNew.setBounds(10, 10, 160, 30);
		btnTrxNew.setMnemonic(KeyEvent.VK_N);
		btnTrxNew.addActionListener(this);
		btnTrxNew.addKeyListener(this);
		
		btnBayar = new JButton("Bayar");
		panel.add(btnBayar);
		btnBayar.setBounds(10, 49, 160, 30);
		btnBayar.setMnemonic(KeyEvent.VK_P);
		btnBayar.addActionListener(this);
		btnBayar.addKeyListener(this);
		
		btnBatal = new JButton("Batal");
		panel.add(btnBatal);
		btnBatal.setEnabled(false);
		btnBatal.setBounds(10, 86, 160, 30);
		btnBatal.setMnemonic(KeyEvent.VK_C);
		btnBatal.addActionListener(this);
		btnBatal.addKeyListener(this);
		
		JSeparator separator1 = new JSeparator();
		separator1.setBackground(new Color(192, 192, 192));
		separator1.setBounds(10, 126, 160, 2);
		panel.add(separator1);
		
		JLabel lblKasir = new JLabel("Kasir: ");
		lblKasir.setFont(new Font("Tahoma", Font.PLAIN, 13));
		lblKasir.setBounds(10, 136, 159, 20);
		panel.add(lblKasir);
		
		JLabel lblKasirValue = new JLabel(kasirValue);
		lblKasirValue.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblKasirValue.setBounds(10, 154, 160, 23);
		panel.add(lblKasirValue);
		
		JLabel lblShift = new JLabel("Shift: ");
		lblShift.setFont(new Font("Tahoma", Font.PLAIN, 13));
		lblShift.setBounds(10, 182, 46, 20);
		panel.add(lblShift);
		
		JLabel lblShiftvalue = new JLabel(shiftValue);
		lblShiftvalue.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblShiftvalue.setBounds(10, 200, 160, 23);
		panel.add(lblShiftvalue);
		
		JSeparator separator2 = new JSeparator();
		separator2.setBackground(Color.LIGHT_GRAY);
		separator2.setBounds(10, 233, 160, 2);
		panel.add(separator2);
		
		return panel;
	}
	
	
	@SuppressWarnings({ "rawtypes", "unchecked"})
	private JPanel rightComponents(){
		JPanel panel = new JPanel();
		panel.setLayout(new BorderLayout());
		
		JPanel panel_1 = new JPanel();
		panel.add(panel_1, BorderLayout.NORTH);
		panel_1.setLayout(new BorderLayout(0, 0));
		panel_1.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
		
		JPanel panel_3 = new JPanel();
		panel_3.setBorder(new EmptyBorder(10, 0, 10, 0));
		panel_1.add(panel_3, BorderLayout.WEST);
		panel_3.setLayout(new GridLayout(2, 3));
		
		JLabel lblNoNota = new JLabel("  Nomor NOTA : ");
		lblNoNota.setFont(new Font("Tahoma", Font.BOLD, 14));
		panel_3.add(lblNoNota);
		
		lblNoNotaValue = new JLabel("-");
		lblNoNotaValue.setFont(new Font("Tahoma", Font.BOLD, 14));
		panel_3.add(lblNoNotaValue);
		
		JLabel lblTitikDua2 = new JLabel(": ");
		lblTitikDua2.setFont(new Font("Tahoma", Font.BOLD, 14));
		
		JLabel lblTypeTrx = new JLabel("  Type Transaksi : ");
		lblTypeTrx.setFont(new Font("Tahoma", Font.BOLD, 14));
		panel_3.add(lblTypeTrx);
		
		comboBoxTrxType = new JComboBox();
		comboBoxTrxType.setModel(new DefaultComboBoxModel(new String[] {"-", AppUtil.TYPE_TRX_BEBAS, AppUtil.TYPE_TRX_RESEP}));
		comboBoxTrxType.addActionListener(this);
		panel_3.add(comboBoxTrxType);
		
		JPanel panel_4 = new JPanel();
		panel_4.setPreferredSize(new Dimension(300, 0));
		panel_4.setBackground(new Color(0, 0, 255));
		panel_1.add(panel_4, BorderLayout.EAST);
		
		lblTotal = new JLabel("0");
		lblTotal.setForeground(new Color(255, 255, 0));
		lblTotal.setHorizontalAlignment(SwingConstants.RIGHT);
		lblTotal.setFont(new Font("Tahoma", Font.BOLD, 33));
		lblTotal.setToolTipText("Total");
		lblTotal.setBorder(new EmptyBorder(10, 0, 0, 2));
		panel_4.add(lblTotal);
		
		JPanel panel_2 = new JPanel();
		panel.add(panel_2, BorderLayout.CENTER);
		panel_2.setLayout(new BorderLayout());
		
		JPanel panel_5 = new JPanel();
		panel_2.add(panel_5, BorderLayout.NORTH);
		panel_5.setLayout(new BorderLayout());
		
		JPanel panel_7 = new JPanel();
		panel_5.add(panel_7, BorderLayout.WEST);
		
		btnAddProd = new JButton("Tambah");
		btnAddProd.addActionListener(this);
		btnAddProd.addKeyListener(this);
		btnAddProd.setMnemonic(AppUtil.MNEMONIC_TAMBAH);
		btnAddProd.setToolTipText("ALT + T");
		panel_7.add(btnAddProd);
		
		btnEditQuantity = new JButton("Edit Quantity");
		btnEditQuantity.addActionListener(this);
		btnEditQuantity.addKeyListener(this);
		btnEditQuantity.setMnemonic(KeyEvent.VK_Q);
		btnEditQuantity.setToolTipText("ALT + Q");
		panel_7.add(btnEditQuantity);
		
		btnEditDiscount = new JButton("Edit Discount");
		/*btnEditDiscount.addActionListener(this);
		btnEditDiscount.addKeyListener(this);
		btnEditDiscount.setMnemonic(KeyEvent.VK_D);
		btnEditDiscount.setToolTipText("ALT + D");
		panel_7.add(btnEditDiscount);*/
		
		btnEditSc = new JButton("Edit SC");
		btnEditSc.addActionListener(this);
		btnEditSc.addKeyListener(this);
		btnEditSc.setMnemonic(KeyEvent.VK_S);
		btnEditSc.setToolTipText("ALT + S");
		panel_7.add(btnEditSc);
		
		btnHapusProd = new JButton("Hapus");
		btnHapusProd.addActionListener(this);
		btnHapusProd.addKeyListener(this);
		btnHapusProd.setMnemonic(AppUtil.MNEMONIC_HAPUS);
		btnHapusProd.setToolTipText("ALT + H");
		panel_7.add(btnHapusProd);
		
		JScrollPane panel_6 = panel_6();
		panel_2.add(panel_6, BorderLayout.CENTER);
		
		JPanel panel_8 = new JPanel();
		panel.add(panel_8, BorderLayout.SOUTH);
		panel_8.setBorder(new LineBorder(new Color(192, 192, 192), 1, true));
		BorderLayout bl_panel_8 = new BorderLayout();
		bl_panel_8.setVgap(10);
		bl_panel_8.setHgap(10);
		panel_8.setLayout(bl_panel_8);
		
		JPanel panel_9 = new JPanel();
		panel_9.setBorder(new EmptyBorder(3, 5, 3, 1));
		panel_8.add(panel_9, BorderLayout.CENTER);
		panel_9.setLayout(new BorderLayout(0, 0));
		
		JPanel panel_19 = new JPanel();
		panel_19.setBorder(new LineBorder(Color.GRAY, 1, true));
		panel_9.add(panel_19, BorderLayout.CENTER);
		panel_19.setLayout(new BorderLayout());
		panel_19.add(new KetForPOSChannel());
		
		JPanel panel_10 = new JPanel();
		panel_8.add(panel_10, BorderLayout.EAST);
		
		JPanel panel_11 = new JPanel();
		panel_11.setBorder(new MatteBorder(0, 1, 0, 0, (Color) new Color(128, 128, 128)));
		panel_10.add(panel_11);
		panel_11.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		
		JPanel panel_12 = new JPanel();
		panel_11.add(panel_12);
		panel_12.setLayout(new GridLayout(0, 2, 0, 2));
		
		JLabel lblRu = new JLabel("RU");
		panel_12.add(lblRu);
		lblRu.setFont(new Font("Tahoma", Font.PLAIN, 13));
		
		textFieldRU = new JTextField();
		textFieldRU.setEnabled(false);
		panel_12.add(textFieldRU);
		textFieldRU.setHorizontalAlignment(SwingConstants.RIGHT);
		textFieldRU.setFont(new Font("Tahoma", Font.BOLD, 12));
		textFieldRU.setColumns(10);
		
		JLabel lblTotalObat = new JLabel("Total Obat");
		panel_12.add(lblTotalObat);
		lblTotalObat.setFont(new Font("Tahoma", Font.PLAIN, 13));
		
		textFieldTotalObat = new JTextField();
		textFieldTotalObat.setEnabled(false);
		panel_12.add(textFieldTotalObat);
		textFieldTotalObat.setHorizontalAlignment(SwingConstants.RIGHT);
		textFieldTotalObat.setFont(new Font("Tahoma", Font.BOLD, 12));
		textFieldTotalObat.setColumns(10);
		
		JSeparator separator = new JSeparator();
		panel_12.add(separator);
		
		JSeparator separator_1 = new JSeparator();
		panel_12.add(separator_1);
		
		JLabel lblUpAsuransiPersen = new JLabel("Up Asuransi (%)");
		panel_12.add(lblUpAsuransiPersen);
		lblUpAsuransiPersen.setFont(new Font("Tahoma", Font.PLAIN, 13));
		
		textFieldUpAsrPersen = new JTextField();
		panel_12.add(textFieldUpAsrPersen);
		textFieldUpAsrPersen.setFont(new Font("Tahoma", Font.PLAIN, 12));
		textFieldUpAsrPersen.setColumns(10);
		textFieldUpAsrPersen.addKeyListener(this);
		textFieldUpAsrPersen.addFocusListener(this);
		
		JLabel lblUpAsuransiRp = new JLabel("Up Asuransi (Rp)");
		panel_12.add(lblUpAsuransiRp);
		lblUpAsuransiRp.setFont(new Font("Tahoma", Font.PLAIN, 13));
		
		textFieldUpAsrRp = new JTextField();
		textFieldUpAsrRp.setEnabled(false);
		panel_12.add(textFieldUpAsrRp);
		textFieldUpAsrRp.setHorizontalAlignment(SwingConstants.RIGHT);
		textFieldUpAsrRp.setFont(new Font("Tahoma", Font.PLAIN, 12));
		textFieldUpAsrRp.setColumns(10);
		
		JSeparator separator_2 = new JSeparator();
		panel_12.add(separator_2);
		
		JSeparator separator_3 = new JSeparator();
		panel_12.add(separator_3);
		
		JLabel lblDiscountPersen = new JLabel("Discount (%)");
		panel_12.add(lblDiscountPersen);
		lblDiscountPersen.setFont(new Font("Tahoma", Font.PLAIN, 13));
		
		textFieldDiscountPersen = new JTextField();
		panel_12.add(textFieldDiscountPersen);
		textFieldDiscountPersen.setFont(new Font("Tahoma", Font.PLAIN, 12));
		textFieldDiscountPersen.setColumns(10);
		textFieldDiscountPersen.addKeyListener(this);
		textFieldDiscountPersen.addFocusListener(this);
		
		JLabel lblDiscountrp = new JLabel("Discount (Rp)");
		panel_12.add(lblDiscountrp);
		lblDiscountrp.setFont(new Font("Tahoma", Font.PLAIN, 13));
		
		textFieldDiscountRp = new JTextField();
		textFieldDiscountRp.setEnabled(false);
		panel_12.add(textFieldDiscountRp);
		textFieldDiscountRp.setHorizontalAlignment(SwingConstants.RIGHT);
		textFieldDiscountRp.setFont(new Font("Tahoma", Font.PLAIN, 12));
		textFieldDiscountRp.setColumns(10);
		
		JPanel panel_13 = new JPanel();
		panel_13.setBorder(new MatteBorder(0, 1, 0, 0, (Color) Color.GRAY));
		panel_10.add(panel_13);
		BorderLayout bl_panel_13 = new BorderLayout();
		bl_panel_13.setVgap(5);
		bl_panel_13.setHgap(5);
		panel_13.setLayout(bl_panel_13);
		
		JPanel panel_14 = new JPanel();
		panel_14.setBorder(new EmptyBorder(0, 5, 0, 0));
		panel_13.add(panel_14, BorderLayout.NORTH);
		panel_14.setLayout(new GridLayout(0, 2, 0, 2));
		
		JLabel lblBiayaDokter = new JLabel("Biaya Dokter");
		lblBiayaDokter.setFont(new Font("Tahoma", Font.PLAIN, 13));
		panel_14.add(lblBiayaDokter);
		
		textFieldBiayaDokter = new JTextField();
		textFieldBiayaDokter.setHorizontalAlignment(SwingConstants.RIGHT);
		textFieldBiayaDokter.setFont(new Font("Tahoma", Font.PLAIN, 12));
		panel_14.add(textFieldBiayaDokter);
		textFieldBiayaDokter.setColumns(10);
		textFieldBiayaDokter.addKeyListener(this);
		textFieldBiayaDokter.addFocusListener(this);
		
		JLabel lblBiayaTindakan = new JLabel("Biaya Tindakan");
		lblBiayaTindakan.setFont(new Font("Tahoma", Font.PLAIN, 13));
		panel_14.add(lblBiayaTindakan);
		
		textFieldBiayaTindakan = new JTextField();
		textFieldBiayaTindakan.setHorizontalAlignment(SwingConstants.RIGHT);
		textFieldBiayaTindakan.setFont(new Font("Tahoma", Font.PLAIN, 12));
		panel_14.add(textFieldBiayaTindakan);
		textFieldBiayaTindakan.setColumns(10);
		textFieldBiayaTindakan.addKeyListener(this);
		textFieldBiayaTindakan.addFocusListener(this);
		
		JLabel lblBiayaLab = new JLabel("Biaya Laboratorium  ");
		lblBiayaLab.setFont(new Font("Tahoma", Font.PLAIN, 13));
		panel_14.add(lblBiayaLab);
		
		textFieldBiayaLab = new JTextField();
		textFieldBiayaLab.setHorizontalAlignment(SwingConstants.RIGHT);
		textFieldBiayaLab.setFont(new Font("Tahoma", Font.PLAIN, 12));
		panel_14.add(textFieldBiayaLab);
		textFieldBiayaLab.setColumns(10);
		textFieldBiayaLab.addKeyListener(this);
		textFieldBiayaLab.addFocusListener(this);
		
		JLabel lblBiayaAdm = new JLabel("Biaya Administrasi");
		lblBiayaAdm.setFont(new Font("Tahoma", Font.PLAIN, 13));
		panel_14.add(lblBiayaAdm);
		
		textFieldBiayaAdm = new JTextField();
		textFieldBiayaAdm.setFont(new Font("Tahoma", Font.PLAIN, 12));
		textFieldBiayaAdm.setHorizontalAlignment(SwingConstants.RIGHT);
		panel_14.add(textFieldBiayaAdm);
		textFieldBiayaAdm.setColumns(10);
		textFieldBiayaAdm.addKeyListener(this);
		textFieldBiayaAdm.addFocusListener(this);
		
		JSeparator separator_4 = new JSeparator();
		panel_14.add(separator_4);
		
		JSeparator separator_5 = new JSeparator();
		panel_14.add(separator_5);
		
		JLabel lblSpace1 = new JLabel("");
		lblSpace1.setFont(new Font("Tahoma", Font.PLAIN, 13));
		panel_14.add(lblSpace1);
		
		JLabel lblSpace2 = new JLabel("");
		lblSpace2.setFont(new Font("Tahoma", Font.PLAIN, 13));
		panel_14.add(lblSpace2);
		
		JLabel lblSubtotal = new JLabel("Sub-Total");
		panel_14.add(lblSubtotal);
		lblSubtotal.setFont(new Font("Tahoma", Font.PLAIN, 13));
		
		textFieldSubTotal = new JTextField();
		textFieldSubTotal.setEnabled(false);
		panel_14.add(textFieldSubTotal);
		textFieldSubTotal.setHorizontalAlignment(SwingConstants.RIGHT);
		textFieldSubTotal.setFont(new Font("Tahoma", Font.BOLD, 12));
		textFieldSubTotal.setColumns(10);
		
		JLabel lblMisc = new JLabel("Misc");
		panel_14.add(lblMisc);
		lblMisc.setFont(new Font("Tahoma", Font.PLAIN, 13));
		
		textFieldMisc = new JTextField();
		panel_14.add(textFieldMisc);
		textFieldMisc.setHorizontalAlignment(SwingConstants.RIGHT);
		textFieldMisc.setFont(new Font("Tahoma", Font.PLAIN, 12));
		textFieldMisc.setColumns(10);
		textFieldMisc.addKeyListener(this);
		textFieldMisc.addFocusListener(this);
		
		JPanel panel_15 = new JPanel();
		panel_15.setBorder(new MatteBorder(0, 1, 0, 0, (Color) Color.GRAY));
		panel_10.add(panel_15);
		panel_15.setLayout(new BorderLayout(5, 5));
		
		JPanel panel_16 = new JPanel();
		panel_16.setBorder(new EmptyBorder(0, 5, 0, 0));
		panel_15.add(panel_16, BorderLayout.NORTH);
		panel_16.setLayout(new BorderLayout(0, 0));
		
		JPanel panel_17 = new JPanel();
		panel_17.setBorder(new TitledBorder(null, "Dokter", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_16.add(panel_17, BorderLayout.NORTH);
		panel_17.setLayout(new GridLayout(0, 2, 0, 2));
		
		JLabel lblDokterNama = new JLabel(" Nama ");
		lblDokterNama.setFont(new Font("Tahoma", Font.PLAIN, 13));
		panel_17.add(lblDokterNama);
		
		textFieldDokter = new JTextField();
		textFieldDokter.setEnabled(false);
		panel_17.add(textFieldDokter);
		textFieldDokter.setColumns(10);
		
		JLabel lblNewLabel = new JLabel("");
		panel_17.add(lblNewLabel);
		
		btnDokter = new JButton("Add/Edit/Del");
		panel_17.add(btnDokter);
		btnDokter.setMnemonic(KeyEvent.VK_K);
		btnDokter.addActionListener(this);
		btnDokter.addKeyListener(this);
		
		JPanel panel_18 = new JPanel();
		panel_18.setBorder(new TitledBorder(null, "Pasien/Pelanggan", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_16.add(panel_18, BorderLayout.SOUTH);
		panel_18.setLayout(new GridLayout(0, 2, 0, 2));
		
		JLabel lblCustNama = new JLabel(" Nama");
		lblCustNama.setFont(new Font("Tahoma", Font.PLAIN, 13));
		panel_18.add(lblCustNama);
		
		textFieldCustNama = new JTextField();
		textFieldCustNama.setEnabled(false);
		textFieldCustNama.setFont(new Font("Tahoma", Font.PLAIN, 12));
		panel_18.add(textFieldCustNama);
		textFieldCustNama.setColumns(10);
		
		JLabel lblAtasNama = new JLabel(" Atas Nama ");
		lblAtasNama.setFont(new Font("Tahoma", Font.PLAIN, 13));
		panel_18.add(lblAtasNama);
		
		textFieldCustAtasNama = new JTextField();
		textFieldCustAtasNama.setEnabled(false);
		textFieldCustAtasNama.setFont(new Font("Tahoma", Font.PLAIN, 12));
		panel_18.add(textFieldCustAtasNama);
		textFieldCustAtasNama.setColumns(10);
		
		JLabel lblNewLabel_3 = new JLabel("");
		panel_18.add(lblNewLabel_3);
		
		btnCust = new JButton("Add/Edit/Del");
		panel_18.add(btnCust);
		btnCust.setMnemonic(KeyEvent.VK_L);
		btnCust.addActionListener(this);
		btnCust.addKeyListener(this);
		
		return panel;
	}
	
	private void firstConditionForComp(){
		btnTrxNew.setEnabled(true);
		btnBayar.setEnabled(false);
		btnBatal.setEnabled(false);
		comboBoxTrxType.setEnabled(false);
		lblNoNotaValue.setText("-");
		btnAddProd.setEnabled(false);
		btnEditQuantity.setEnabled(false);
		btnEditSc.setEnabled(false);
		btnEditDiscount.setEnabled(false);
		btnHapusProd.setEnabled(false);
		table.setEnabled(false);
		textFieldUpAsrPersen.setEnabled(false);
		textFieldDiscountPersen.setEnabled(false);
		textFieldBiayaDokter.setEnabled(false);
		textFieldBiayaTindakan.setEnabled(false);
		textFieldBiayaLab.setEnabled(false);
		textFieldBiayaAdm.setEnabled(false);
		textFieldMisc.setEnabled(false);
		
		comboBoxTrxType.setSelectedIndex(0);
		lblTotal.setText("0");
		textFieldRU.setText("");
		textFieldTotalObat.setText("");
		textFieldUpAsrPersen.setText("");
		textFieldUpAsrRp.setText("");
		textFieldDiscountPersen.setText("");
		textFieldDiscountRp.setText("");
		textFieldBiayaDokter.setText("");
		textFieldBiayaTindakan.setText("");
		textFieldBiayaLab.setText("");
		textFieldBiayaAdm.setText("");
		textFieldSubTotal.setText("");
		textFieldMisc.setText("");
		
		btnDokter.setEnabled(false);
		btnCust.setEnabled(false);
		
		tableModel.removeRowAll();
		currentSalesTrx = null;
		modelRow = -1;
	}
	
	@SuppressWarnings("serial")
	private JScrollPane panel_6(){
		JScrollPane scrollPane = new JScrollPane();
		
		String[] columnNames = {"Kode Barang", "Nama Barang", "Quantity", "Harga Satuan (Rp)", "SC (Rp)", /*"Discount (%)", */"Jumlah (Rp)"};
		tableModel = new TableModelCustom(columnNames);
		
		table = new JTable(){
			@Override
			public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
				JLabel label = (JLabel) super.prepareRenderer(renderer, row, column);
				
				if(column==2 || column==3 || column==4 || column==5 || column==6){
					label.setHorizontalAlignment(JLabel.RIGHT);
				}else{
					label.setHorizontalAlignment(JLabel.LEFT);
				}
				
				return label;
			}
		};
		table.setFont(new Font("Tahoma", Font.PLAIN, 13));
		table.setModel(tableModel);
		table.setEnabled(true);
		table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
			@SuppressWarnings("rawtypes")
			@Override
			public void valueChanged(ListSelectionEvent arg0) {
				int viewRow = table.getSelectedRow();
				if(viewRow>-1){
					modelRow = table.convertRowIndexToModel(viewRow);
					
					Vector v = (Vector) tableModel.getRowVector().get(modelRow);
					if(v!=null){
						
					}
					
				}
			}
		});
		scrollPane.setViewportView(table);
		
		String actionMapKeyDel = "key_del";
		String actionMapKeySpace = "key_space";
		
		table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), actionMapKeyDel);
		table.getActionMap().put(actionMapKeyDel, new AbstractAction() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				//System.out.println("table row action");
				//System.out.println("modelRow: "+modelRow);
				deleteSalesTrxObat();
			}
		});
		
		table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), actionMapKeySpace);
		table.getActionMap().put(actionMapKeySpace, new AbstractAction() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				//System.out.println("space table row action");
				//System.out.println("modelRow: "+modelRow);
				String[] choices = {"Edit Quantity Item", "Edit Discount Item"};
				String result = (String) JOptionPane.showInputDialog(null, null, "Select Option", JOptionPane.PLAIN_MESSAGE, null, choices, 0);
				System.out.println("result: "+result);
				
				if(result!=null){
					if(result.equalsIgnoreCase(choices[0])){
						editQuantityItem();
					}else if(result.equalsIgnoreCase(choices[1])){
						editDiscountItem();
					}
				}
			}
		});
		
		return scrollPane;
	}
	
	private boolean checkTypeTrx(){
		String selected = (String) comboBoxTrxType.getSelectedItem();
		if(selected.equalsIgnoreCase("-")){
			JOptionPane.showMessageDialog(null, "Silahkan pilih type transaksi", "Error", JOptionPane.ERROR_MESSAGE);
			comboBoxTrxType.requestFocus();
			return false;
		}
		return true;
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	private Vector vItemList(String productCode, String productName, int quantity, int hargaUnit, int sc, int discount, int sumHarga){
		Vector v = new Vector();
		v.add(productCode);
		v.add(productName);
		v.add(Integer.toString(quantity));
		v.add(AppUtil.formatStringIDR(hargaUnit));
		v.add(Integer.toString(sc));
		//v.add(Integer.toString(discount));
		v.add(AppUtil.formatStringIDR(sumHarga));
		
		return v;
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void insertItem(Product product, int quantity){
		
		BigDecimal harga = product.getPriceSell();
		BigDecimal amountSC = BigDecimal.ZERO;
		int discount = 0;
		
		String trxType = (String) comboBoxTrxType.getSelectedItem();
		if(trxType.equalsIgnoreCase(AppUtil.TYPE_TRX_RESEP)){
			amountSC = sCValue();
		}
		
		BigDecimal sumHarga = AppUtil.amountSalesTrxObat(harga, quantity, amountSC, discount);
		
		Vector v = vItemList(product.getProductCode(), product.getProductName(), quantity, harga.intValue(), amountSC.intValue(), discount, sumHarga.intValue());
		
		SalesTrxObat salesTrxObat = new SalesTrxObat();
		salesTrxObat.setSalesTrx(currentSalesTrx);
		salesTrxObat.setProduct(product);
		salesTrxObat.setProductCode(product.getProductCode());
		salesTrxObat.setProductName(product.getProductName());
		salesTrxObat.setAmountUnitPrice(harga);
		salesTrxObat.setQuantity(quantity);
		salesTrxObat.setAmountSC(amountSC);
		salesTrxObat.setAmountTrxObat(sumHarga);
		salesTrxObat.setDiscount(discount);
		salesTrxObat.setAmountDiscount(new BigDecimal(discount));
		
		v.add(salesTrxObat);
		
		tableModel.insertData(v);
		
		SalesTrxObatDao stoDao = new SalesTrxObatDao();
		if(stoDao.saveOrUpdate(salesTrxObat)){
			//subtractStokProduct(product, quantity);
		}
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void updateItemSame(int rowIndex, SalesTrxObat salesTrxObat, int quantity){
		Product product 			= salesTrxObat.getProduct();
		BigDecimal hargaUnit 		= product.getPriceSell();
		BigDecimal amountSC 		= salesTrxObat.getAmountSC();
		int diskon 					= salesTrxObat.getDiscount();
		int quantityBefore 			= salesTrxObat.getQuantity();
		int quantityUpdate 			= quantityBefore + quantity;
		
		BigDecimal sumHargaUpdate = AppUtil.amountSalesTrxObat(hargaUnit, quantityUpdate, amountSC, diskon);
		
		salesTrxObat.setQuantity(quantity);
		salesTrxObat.setAmountTrxObat(sumHargaUpdate);
		
		SalesTrxObatDao stoDao = new SalesTrxObatDao();
		if(stoDao.saveOrUpdate(salesTrxObat)){
			Vector v = vItemList(product.getProductCode(), product.getProductName(), quantityUpdate, hargaUnit.intValue(), amountSC.intValue(), diskon, sumHargaUpdate.intValue());
			v.add(salesTrxObat);
			
			tableModel.updateData(rowIndex, v);
			
			//subtractStokProduct(product, quantity);
		}	
		
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void updateItemQuantity(int rowIndex, SalesTrxObat salesTrxObat, int quantity){
		int quantityBefore = salesTrxObat.getQuantity();
		if(quantity!=quantityBefore){
			BigDecimal amountSC 		= salesTrxObat.getAmountSC();
			BigDecimal hargaSatuan 		= salesTrxObat.getAmountUnitPrice();
			int diskon 					= salesTrxObat.getDiscount(); 
			
			BigDecimal sumHargaUpdate = AppUtil.amountSalesTrxObat(hargaSatuan, quantity, amountSC, diskon);
			BigDecimal amountDiscount = AppUtil.amountPersentasi(diskon, sumHargaUpdate, 0);
			
			salesTrxObat.setQuantity(quantity);
			salesTrxObat.setAmountDiscount(amountDiscount);
			salesTrxObat.setAmountTrxObat(sumHargaUpdate);
			
			SalesTrxObatDao stoDao = new SalesTrxObatDao();
			if(stoDao.saveOrUpdate(salesTrxObat)){
				Product product = salesTrxObat.getProduct();
				
				Vector v = vItemList(product.getProductCode(), product.getProductName(), quantity, hargaSatuan.intValue(), amountSC.intValue(), diskon, sumHargaUpdate.intValue());
				v.add(salesTrxObat);
				
				tableModel.updateData(rowIndex, v);
				
				int quantityAfter = quantity-quantityBefore;
				//subtractStokProduct(product, quantityAfter);
				
			}else{
				JOptionPane.showMessageDialog(null, "Update quantity error", "Error", JOptionPane.ERROR_MESSAGE);
			}
		}
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void updateItemDiscount(int rowIndex, SalesTrxObat salesTrxObat, int discount, BigDecimal amountDiscount, BigDecimal sumHargaUpdate){
		int discoutBefore = salesTrxObat.getDiscount();
		if(discoutBefore!=discount){
			salesTrxObat.setDiscount(discount);
			salesTrxObat.setAmountDiscount(amountDiscount);
			salesTrxObat.setAmountTrxObat(sumHargaUpdate);
			
			SalesTrxObatDao stoDao = new SalesTrxObatDao();
			if(stoDao.saveOrUpdate(salesTrxObat)){
				Product product = salesTrxObat.getProduct();
				int quantity 	= salesTrxObat.getQuantity();
				int hargaSatuan = salesTrxObat.getAmountUnitPrice().intValue();
				
				Vector v = vItemList(product.getProductCode(), product.getProductName(), quantity, hargaSatuan, salesTrxObat.getAmountSC().intValue(), discount, sumHargaUpdate.intValue());
				v.add(salesTrxObat);
				tableModel.updateData(rowIndex, v);
			}	
		}
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void updateItemSc(int rowIndex, SalesTrxObat salesTrxObat, int scUpdate){
		int scBefore = salesTrxObat.getAmountSC().intValue();
		if(scBefore!=scUpdate){
			BigDecimal hargaSatuan = salesTrxObat.getAmountUnitPrice();
			BigDecimal amountScUpdate = new BigDecimal(scUpdate);
			int quantity = salesTrxObat.getQuantity();
			int diskon 	= salesTrxObat.getDiscount(); 
			BigDecimal sumHargaUpdate = AppUtil.amountSalesTrxObat(hargaSatuan, quantity, amountScUpdate, diskon);
			
			salesTrxObat.setAmountSC(amountScUpdate);
			salesTrxObat.setAmountTrxObat(sumHargaUpdate);
			
			SalesTrxObatDao dao = new SalesTrxObatDao();
			if(dao.saveOrUpdate(salesTrxObat)){
				Product product = salesTrxObat.getProduct();
				
				Vector v = vItemList(product.getProductCode(), product.getProductName(), quantity, hargaSatuan.intValue(), scUpdate, diskon, sumHargaUpdate.intValue());
				v.add(salesTrxObat);
				tableModel.updateData(rowIndex, v);
			}
		}
	}
	
	/*private void subtractStokProduct(Product product, int quantity){
		int stokUpdate = product.getAvailableStock() - quantity;
		product.setAvailableStock(stokUpdate);
		
		ProductDao productDao = new ProductDao();
		productDao.saveOrUpdate(product);
	}*/
	
	private void updateTypeTrx(){
		String trxType = (String) comboBoxTrxType.getSelectedItem();
		
		SalesTrx st = this.currentSalesTrx;
		st.setTrxType(trxType);
		
		SalesTrxDao dao = new SalesTrxDao();
		if(dao.saveOrUpdate(st)){
			this.currentSalesTrx = st;
		}
	}
	
	private BigDecimal sCValue(){
		return new BigDecimal(1000);
	}
	
	private void updateRUAndTotalObat(){
		SalesTrxObatDao stoDao = new SalesTrxObatDao();
		BigDecimal amountTrxObat = stoDao.sumAmountTrxBySalesTrx(currentSalesTrx);
		if(amountTrxObat==null){
			amountTrxObat = BigDecimal.ZERO;
		}
				
		BigDecimal amountTrxObatUpdate = amountTrxObat.setScale(0);
		BigDecimal rounding = AppUtil.roundingDozensUp(amountTrxObatUpdate);
		BigDecimal difference = rounding.subtract(amountTrxObat).setScale(0);
		
		SalesTrx st = this.currentSalesTrx;
		st.setAmountRU(difference);
		st.setAmountSalesObat(amountTrxObat);
		
		SalesTrxDao stDao = new SalesTrxDao();
		if(stDao.saveOrUpdate(st)){
			this.currentSalesTrx = st;
		}
		
		textFieldRU.setText(AppUtil.formatStringIDR(difference.intValue()));
		textFieldTotalObat.setText(AppUtil.formatStringIDR(rounding.intValue()));
		
		updateSubTotal();
	}
	
	private void updateUpAsr(){
		String valPersenStr = textFieldUpAsrPersen.getText();
		if(valPersenStr.trim().isEmpty()){
			valPersenStr = "0";
		}
		
		String removeDot = AppUtil.removeCharacters(valPersenStr, ".");
		if(!AppUtil.isNumber(removeDot)){
			JOptionPane.showMessageDialog(null, "Invalid.\nSilahkan masukkan angka", "Error", JOptionPane.ERROR_MESSAGE);
			return;
		}
		
		BigDecimal bg = amountUpAsr();
		
		SalesTrx st = this.currentSalesTrx;
		st.setObatUpAsr(Integer.parseInt(valPersenStr));
		st.setAmountObatUpAsr(bg);
		
		this.currentSalesTrx = st;
		updateSubTotal();
	}
	
	private void updateDiscount(){
		String valPersenStr = textFieldDiscountPersen.getText();
		if(valPersenStr.trim().isEmpty()){
			valPersenStr = "0";
		}
		
		String removeDot = AppUtil.removeCharacters(valPersenStr, ".");
		if(!AppUtil.isNumber(removeDot)){
			JOptionPane.showMessageDialog(null, "Invalid.\nSilahkan masukkan angka", "Error", JOptionPane.ERROR_MESSAGE);
			return;
		}
		
		BigDecimal bg = amountDiscount();
		
		SalesTrx st = this.currentSalesTrx;
		st.setObatDiscount(Integer.parseInt(valPersenStr));
		st.setAmountObatDiscount(bg);
		
		this.currentSalesTrx = st;
		updateSubTotal();
	}
	
	private void updateBiayaDokter(){
		String valStr = textFieldBiayaDokter.getText();
		if(valStr.trim().isEmpty()){
			valStr = "0";
		}
		
		String removeDot = AppUtil.removeCharacters(valStr, ".");
		if(!AppUtil.isNumber(removeDot)){
			JOptionPane.showMessageDialog(null, "Invalid.\nSilahkan masukkan angka", "Error", JOptionPane.ERROR_MESSAGE);
			return;
		}
		
		SalesTrx st = this.currentSalesTrx;
		st.setAmountDokterService(new BigDecimal(removeDot));
		
		this.currentSalesTrx = st;
		updateSubTotal();
		
		textFieldBiayaDokter.setText(AppUtil.formatStringIDR(Integer.parseInt(removeDot)));
	}
	
	private void updateBiayaTindakan(){
		String valStr = textFieldBiayaTindakan.getText();
		if(valStr.trim().isEmpty()){
			valStr = "0";
		}
		
		String removeDot = AppUtil.removeCharacters(valStr, ".");
		if(!AppUtil.isNumber(removeDot)){
			JOptionPane.showMessageDialog(null, "Invalid.\nSilahkan masukkan angka", "Error", JOptionPane.ERROR_MESSAGE);
			return;
		}
		
		SalesTrx st = this.currentSalesTrx;
		st.setAmountMedicalTreatment(new BigDecimal(removeDot));
		
		this.currentSalesTrx = st;
		updateSubTotal();
		
		textFieldBiayaTindakan.setText(AppUtil.formatStringIDR(Integer.parseInt(removeDot)));
	}
	
	private void updateBiayaLab(){
		String valStr = textFieldBiayaLab.getText();
		if(valStr.trim().isEmpty()){
			valStr = "0";
		}
		
		String removeDot = AppUtil.removeCharacters(valStr, ".");
		if(!AppUtil.isNumber(removeDot)){
			JOptionPane.showMessageDialog(null, "Invalid.\nSilahkan masukkan angka", "Error", JOptionPane.ERROR_MESSAGE);
			return;
		}
		
		SalesTrx st = this.currentSalesTrx;
		st.setAmountLabService(new BigDecimal(removeDot));
		
		this.currentSalesTrx = st;
		updateSubTotal();
		
		textFieldBiayaLab.setText(AppUtil.formatStringIDR(Integer.parseInt(removeDot)));
	}
	
	private void updateBiayaAdm(){
		String valStr = textFieldBiayaAdm.getText();
		if(valStr.trim().isEmpty()){
			valStr = "0";
		}
		
		String removeDot = AppUtil.removeCharacters(valStr, ".");
		if(!AppUtil.isNumber(removeDot)){
			JOptionPane.showMessageDialog(null, "Invalid.\nSilahkan masukkan angka", "Error", JOptionPane.ERROR_MESSAGE);
			return;
		}
		
		SalesTrx st = this.currentSalesTrx;
		st.setAmountAdministration(new BigDecimal(removeDot));
		
		this.currentSalesTrx = st;
		updateSubTotal();
		
		textFieldBiayaAdm.setText(AppUtil.formatStringIDR(Integer.parseInt(removeDot)));
	}
	
	private void updateMisc(){
		String valStr = textFieldMisc.getText();
		if(valStr.trim().isEmpty()){
			valStr = "0";
		}
		
		String removeDot = AppUtil.removeCharacters(valStr, ".");
		if(!AppUtil.isNumber(removeDot)){
			JOptionPane.showMessageDialog(null, "Invalid.\nSilahkan masukkan angka", "Error", JOptionPane.ERROR_MESSAGE);
			return;
		}
		
		SalesTrx st = this.currentSalesTrx;
		st.setAmountMisc(new BigDecimal(removeDot));
		
		this.currentSalesTrx = st;
		updateTotal();
		
		textFieldMisc.setText(AppUtil.formatStringIDR(Integer.parseInt(removeDot)));
	}
	
	private BigDecimal amountUpAsr(){
		String totalObatStr = textFieldTotalObat.getText();
		if(totalObatStr.trim().isEmpty()) totalObatStr = "0";
		String totalObat = AppUtil.removeCharacters(totalObatStr, ".");
		BigDecimal amountObat = new BigDecimal(totalObat);
		
		String valStr = textFieldUpAsrPersen.getText();
		if(valStr.trim().isEmpty()) valStr = "0";
		
		BigDecimal bg = AppUtil.amountPersentasi(Integer.parseInt(valStr), amountObat, 0);
		return bg;
	}
	
	private BigDecimal  amountDiscount(){
		String totalObatStr = textFieldTotalObat.getText();
		if(totalObatStr.trim().isEmpty()) totalObatStr = "0";
		String totalObat = AppUtil.removeCharacters(totalObatStr, ".");
		BigDecimal amountObat = new BigDecimal(totalObat);
		
		String valStr = textFieldDiscountPersen.getText();
		if(valStr.trim().isEmpty()) valStr = "0";
		
		BigDecimal bg = AppUtil.amountPersentasi(Integer.parseInt(valStr), amountObat, 0);
		return bg;
	}
	
	private BigDecimal amounSubTotal(BigDecimal trxObat, BigDecimal RU, BigDecimal obatUpAsr, BigDecimal obatDiskon, BigDecimal doctorServ, 
			BigDecimal medicalTreatment, BigDecimal labServ, BigDecimal adm){
		BigDecimal result = BigDecimal.ZERO;
		
		//sub-total = (totalObat + RU + upAsrObat + biayaDokter + biayaTindakan + biayaLab + biayaAdm) - diskonObat;
		
		BigDecimal sum = trxObat.add(RU).add(obatUpAsr).add(doctorServ).add(medicalTreatment).add(labServ).add(adm);
		BigDecimal kurangiDiskon = sum.subtract(obatDiskon);
		result = kurangiDiskon.setScale(0, RoundingMode.HALF_UP);
		
		return result;
	}
	
	private BigDecimal subTotal(){
		SalesTrx st = this.currentSalesTrx;
		
		BigDecimal amountObat = st.getAmountSalesObat().setScale(0, RoundingMode.HALF_UP);
		System.out.println("amountObat: "+st.getAmountSalesObat());
		
		String ruStr = textFieldRU.getText();
		if(ruStr.trim().isEmpty()) ruStr = "0";
		
		BigDecimal trxObat 		= new BigDecimal(AppUtil.removeCharacters(amountObat.toString(), "."));
		BigDecimal RU 			= new BigDecimal(AppUtil.removeCharacters(ruStr, "."));
		
		BigDecimal obatDiskon	= amountDiscount();
		
		BigDecimal obatUpAsr	= BigDecimal.ZERO;
		BigDecimal doctorServ 	= BigDecimal.ZERO;
		BigDecimal medicTreat 	= BigDecimal.ZERO;
		BigDecimal labServ 		= BigDecimal.ZERO;
		BigDecimal adm 			= BigDecimal.ZERO;
		if(st.getTrxType()!=null && st.getTrxType().equalsIgnoreCase(AppUtil.TYPE_TRX_RESEP)){
			String doctorServStr = textFieldBiayaDokter.getText();
			if(doctorServStr.trim().isEmpty()) doctorServStr = "0";
			
			String medicalTreatStr = textFieldBiayaTindakan.getText();
			if(medicalTreatStr.trim().isEmpty()) medicalTreatStr="0";
			
			String labServStr = textFieldBiayaLab.getText();
			if(labServStr.trim().isEmpty()) labServStr = "0";
			
			String admStr = textFieldBiayaAdm.getText();
			if(admStr.trim().isEmpty()) admStr = "0";
			
			obatUpAsr	= amountUpAsr();
			doctorServ 	= new BigDecimal(AppUtil.removeCharacters(doctorServStr, "."));
			medicTreat	= new BigDecimal(AppUtil.removeCharacters(medicalTreatStr, "."));
			labServ 	= new BigDecimal(AppUtil.removeCharacters(labServStr, "."));
			adm 		= new BigDecimal(AppUtil.removeCharacters(admStr, "."));
		}
		
		BigDecimal subTotal 	= amounSubTotal(trxObat, RU, obatUpAsr, obatDiskon, doctorServ, medicTreat, labServ, adm);
		//BigDecimal subTotal = BigDecimal.ZERO;	
		
		return subTotal;
	}
	
	private void updateSubTotal(){
		BigDecimal subTotal = subTotal();
		textFieldSubTotal.setText(AppUtil.formatStringIDR(subTotal.intValue()));
		
		updateTotal();
	}
	
	private void updateTotal(){
		BigDecimal subTotal = subTotal();
		
		String miscStr = textFieldMisc.getText();
		if(miscStr.trim().isEmpty()) miscStr = "0";
		
		BigDecimal miscBg = new BigDecimal(miscStr);
		BigDecimal totalBg = subTotal.add(miscBg).setScale(0, RoundingMode.HALF_UP);
		
		SalesTrx st = this.currentSalesTrx;
		st.setAmountTrx(totalBg);
		
		SalesTrxDao dao = new SalesTrxDao();
		if(dao.saveOrUpdate(st)){
			lblTotal.setText(AppUtil.formatStringIDR(totalBg.intValue()));
		}
	}
	
	@SuppressWarnings("rawtypes")
	private void deleteSalesTrxObat(){
		Vector v = (Vector) tableModel.getRowVector().elementAt(modelRow);
		SalesTrxObat sto = (SalesTrxObat) v.elementAt(v.size()-1);
		
		SalesTrxObatDao dao = new SalesTrxObatDao();
		if(dao.delete(sto)){
			tableModel.removeRow(modelRow);
			this.modelRow = -1;
			updateRUAndTotalObat();
		}
	}
	
	@SuppressWarnings("rawtypes")
	private void editQuantityItem(){
		Vector v = (Vector) tableModel.getRowVector().elementAt(modelRow);
		SalesTrxObat sto = (SalesTrxObat) v.elementAt(v.size()-1);
		
		boolean isVisible = false;
		if(editTrxObatQuantityDialog!=null){
			isVisible = editTrxObatQuantityDialog.isVisible();
		}
		
		if(isVisible){
			editTrxObatQuantityDialog.toFront();
			editTrxObatQuantityDialog.requestFocus();
		}else{
			editTrxObatQuantityDialog = new EditTrxObatQuantityDialog(this, modelRow, sto);
			editTrxObatQuantityDialog.setVisible(true);
			editTrxObatQuantityDialog.requestFocus();
		}
	}
	
	@SuppressWarnings("rawtypes")
	private void editDiscountItem(){
		Vector v = (Vector) tableModel.getRowVector().elementAt(modelRow);
		SalesTrxObat sto = (SalesTrxObat) v.elementAt(v.size()-1);
		
		boolean isVisible = false;
		if(editTrxObatDiscountDialog!=null){
			isVisible = editTrxObatDiscountDialog.isVisible();
		}
		
		if(isVisible){
			editTrxObatDiscountDialog.toFront();
			editTrxObatDiscountDialog.requestFocus();
		}else{
			editTrxObatDiscountDialog = new EditTrxObatDiscountDialog(this, modelRow, sto);
			editTrxObatDiscountDialog.setVisible(true);
			editTrxObatDiscountDialog.requestFocus();
		}
	}
	
	@SuppressWarnings("rawtypes")
	private void editScItem(){
		Vector v = (Vector) tableModel.getRowVector().elementAt(modelRow);
		SalesTrxObat sto = (SalesTrxObat) v.elementAt(v.size()-1);
		
		boolean isVisible = false;
		if(editTrxObatScDialog!=null){
			isVisible = editTrxObatScDialog.isVisible();
		}
		
		if(isVisible){
			editTrxObatScDialog.toFront();
			editTrxObatDiscountDialog.requestFocus();
		}else{
			editTrxObatScDialog = new EditTrxObatScDialog(this, modelRow, sto);
			editTrxObatScDialog.setVisible(true);
			editTrxObatScDialog.requestFocus();
		}
	}
	
	private void btnTrxNewAction(){
		TrxUniqueNumberBean tunb = AppUtil.generateTrxUniqueNumber("D");
		if(tunb==null){
			JOptionPane.showMessageDialog(null, "Generate Nomor Nota error", "Error", JOptionPane.ERROR_MESSAGE);
		}else{
			lblNoNotaValue.setEnabled(true);
			//lblNoNotaValue.setText(tunb.getUniqueNumber());
			comboBoxTrxType.setEnabled(true);
			comboBoxTrxType.requestFocus();
			btnTrxNew.setEnabled(false);
			btnBayar.setEnabled(true);
			btnBatal.setEnabled(true);
			btnAddProd.setEnabled(true);
			btnEditQuantity.setEnabled(true);
			btnEditSc.setEnabled(true);
			btnEditDiscount.setEnabled(true);
			btnHapusProd.setEnabled(true);
			table.setEnabled(true);
			textFieldDiscountPersen.setEnabled(true);
			textFieldMisc.setEnabled(true);
			btnCust.setEnabled(true);
			
			TransactionUniqueNumber tun = new TransactionUniqueNumber();
			tun.setUniqueNumberId(tunb.getId());
			tun.setCode(tunb.getCode());
			tun.setYear(tunb.getYear());
			tun.setMonth(tunb.getMonth());
			tun.setNumber(tunb.getNumber());
			
			TransactionUniqueNumberDao tunDao = new TransactionUniqueNumberDao();
			tunDao.saveOrUpdate(tun);
			
			String timeStart = CalendarUtil.dateToString_HHMM(shift.getStartTime());
			String timeFinish = CalendarUtil.dateToString_HHMM(shift.getFinishTime());
			
			SalesTrx st = new SalesTrx();
			st.setTrxCode(tunb.getUniqueNumber());
			st.setShiftName(shift.getShiftName());
			st.setShiftTime(timeStart+"-"+timeFinish);
			st.setPaymentStatus(AppUtil.TRANSAKSI_STATUS_BARU);
			st.setAmountSalesObat(BigDecimal.ZERO);
			st.setObatUpAsr(0);
			st.setAmountObatUpAsr(BigDecimal.ZERO);
			st.setObatDiscount(0);
			st.setAmountObatDiscount(BigDecimal.ZERO);
			st.setAmountDokterService(BigDecimal.ZERO);
			st.setAmountMedicalTreatment(BigDecimal.ZERO);
			st.setAmountLabService(BigDecimal.ZERO);
			st.setAmountAdministration(BigDecimal.ZERO);
			st.setAmountRU(BigDecimal.ZERO);
			st.setAmountMisc(BigDecimal.ZERO);
			st.setAmountTrx(BigDecimal.ZERO);
			st.setAmountRefund(BigDecimal.ZERO);
			st.setCreatedDate(Calendar.getInstance(CalendarUtil.tx).getTime());
			st.setCreatedBy(selectedCashier);
			
			SalesTrxDao stDao = new SalesTrxDao();
			if(stDao.saveOrUpdate(st)){
				this.currentSalesTrx = st;
			}
			
		}
	}
	
	private void btnBatalAction(){
		lblNoNotaValue.setEnabled(true);
		lblNoNotaValue.setText("-");
		
		SalesTrx st = this.currentSalesTrx;
		st.setPaymentStatus(AppUtil.TRANSAKSI_STATUS_BATAL);
		
		SalesTrxDao dao = new SalesTrxDao();
		if(dao.saveOrUpdate(st)){
			firstConditionForComp();
			
			SalesTrxObatDao stoDao = new SalesTrxObatDao();
			List<SalesTrxObat> stoList = stoDao.listBySalesTrx(st);
			for(SalesTrxObat sto: stoList){
				int quantity = sto.getQuantity();
				Product p = sto.getProduct();
				
				//subtractStokProduct(p, -quantity);
			}
		}
	}
	
	private void btnBayarAction(){
		boolean isVisible = false;
		if(bayarDialog!=null){
			isVisible = bayarDialog.isVisible();
		}
		
		if(isVisible){
			bayarDialog.toFront();
			bayarDialog.requestFocus();
		}else{
			bayarDialog = new BayarDialog(this, currentSalesTrx);
			bayarDialog.setVisible(true);
			bayarDialog.requestFocus();
		}
	}
	
	private void btnAddProdAction(){
		if(!checkTypeTrx()){
			return;
		}
		
		boolean isVisible = false;
		if(addProductToTrxDialog!=null){
			isVisible = addProductToTrxDialog.isVisible();
		}
		
		if(isVisible){
			addProductToTrxDialog.toFront();
			addProductToTrxDialog.requestFocus();
		}else{
			addProductToTrxDialog = new AddProductToTrxDialog(this);
			addProductToTrxDialog.setVisible(true);
			addProductToTrxDialog.requestFocus();
		}
	}
	
	private void btnEditQuantityAction(){
		if(this.modelRow==-1){
			JOptionPane.showMessageDialog(null, "Silahkan pilih satu item", "Error", JOptionPane.ERROR_MESSAGE);
		}else{
			editQuantityItem();
		}
	}
	
	private void btnEditDiscountAction(){
		if(this.modelRow==-1){
			JOptionPane.showMessageDialog(null, "Silahkan pilih satu item", "Error", JOptionPane.ERROR_MESSAGE);
		}else{
			editDiscountItem();
		}
	}
	
	private void btnEditScAction(){
		if(this.modelRow==-1){
			JOptionPane.showMessageDialog(null, "Silahkan pilih satu item", "Error", JOptionPane.ERROR_MESSAGE);
		}else{
			editScItem();
		}
	}
	
	private void btnHapusProdAction(){
		if(this.modelRow==-1){
			JOptionPane.showMessageDialog(null, "Silahkan pilih satu item", "Error", JOptionPane.ERROR_MESSAGE);
		}else{
			deleteSalesTrxObat();
		}
	}
	
	private void btnDokterAction(){
		boolean isVisible = false;
		if(addDokterDialog!=null){
			isVisible = addDokterDialog.isVisible();
		}
		
		if(isVisible){
			addDokterDialog.toFront();
			addDokterDialog.requestFocus();
		}else{
			addDokterDialog = new AddDokterToTrxDialog(this);
			addDokterDialog.setVisible(true);
			addDokterDialog.requestFocus();
		}
	}
	
	private void btnCustAction(){
		boolean isVisible = false;
		if(inputPatientDialog!=null){
			isVisible = inputPatientDialog.isVisible();
		}
		
		if(isVisible){
			inputPatientDialog.toFront();
			inputPatientDialog.requestFocus();
		}else{
			inputPatientDialog = new InputPatientDialog(this, currentSalesTrx, currentPatient);
			inputPatientDialog.setVisible(true);
			inputPatientDialog.requestFocus();
		}
	}
	
	public JSplitPane getSplitPane() {
		return splitPane;
	}
	
	@Override
	public void actionPerformed(ActionEvent ae) {
		Object obj = ae.getSource();
		
		if(obj==btnTrxNew){
			btnTrxNewAction();
			
		}else if(obj==btnBatal){
			btnBatalAction();
			
		}else if(obj==btnBayar){
			btnBayarAction();
			
		}else if(obj==btnAddProd){
			btnAddProdAction();
			
		}else if(obj==btnEditQuantity){
			btnEditQuantityAction();
			
		}else if(obj==btnEditDiscount){
			btnEditDiscountAction();
			
		}else if(obj==btnEditSc){
			btnEditScAction();
			
		}else if(obj==btnHapusProd){
			btnHapusProdAction();
			
		}else if(obj==comboBoxTrxType){
			String item = (String) comboBoxTrxType.getSelectedItem();
			if(item.equalsIgnoreCase(AppUtil.TYPE_TRX_BEBAS)){
				textFieldUpAsrPersen.setEnabled(false);
				textFieldBiayaDokter.setEnabled(false);
				textFieldBiayaTindakan.setEnabled(false);
				textFieldBiayaLab.setEnabled(false);
				textFieldBiayaAdm.setEnabled(false);
				btnEditSc.setEnabled(false);
				btnDokter.setEnabled(false);
			}else if(item.equalsIgnoreCase(AppUtil.TYPE_TRX_RESEP)){
				textFieldUpAsrPersen.setEnabled(true);
				textFieldBiayaDokter.setEnabled(true);
				textFieldBiayaTindakan.setEnabled(true);
				textFieldBiayaLab.setEnabled(true);
				textFieldBiayaAdm.setEnabled(true);
				btnEditSc.setEnabled(true);
				btnDokter.setEnabled(true);
			}
		}else if(obj==btnCust){
			btnCustAction();
			
		}else if(obj==btnDokter){
			btnDokterAction();
			
		}
	}
	
	@SuppressWarnings({ "rawtypes" })
	@Override
	public void insertProduct(Product product, int quantity) {
		this.modelRow = -1;
		comboBoxTrxType.setEnabled(false);
		updateTypeTrx();
		
		int rowIndex = -1;
		SalesTrxObat sto = null;
		
		Vector vector = tableModel.getRowVector();
		for(int i=0;i<vector.size();i++){
			Vector vIsi = (Vector) vector.elementAt(i);
			sto = (SalesTrxObat) vIsi.elementAt(vIsi.size()-1);
			if(sto.getProduct().getProductCode().equalsIgnoreCase(product.getProductCode())){
				rowIndex = i;
			}
		}
		
		if(rowIndex!=-1){
			updateItemSame(rowIndex, sto, quantity);
		}else{
			insertItem(product, quantity);
		}
		
		updateRUAndTotalObat();
		
	}
	
	@Override
	public void updateProduct(HashMap<String, Object> hm) {
		try {
			int update_for 	 = (int) hm.get("update_for");
			int rowIndex 	 = (int) hm.get("rowIndex");
			SalesTrxObat sto = (SalesTrxObat) hm.get("salesTrxObat");
			
			if(update_for==UPDATE_QUANTITY){
				int quantity = (int) hm.get("quantity");
				updateItemQuantity(rowIndex, sto, quantity);
			}else if(update_for==UPDATE_DISCOUNT){
				int discount = (int) hm.get("discount");
				BigDecimal amountDiscount = (BigDecimal) hm.get("discountAmount");
				BigDecimal sumHargaUpdate = (BigDecimal) hm.get("sumHargaUpdate");
				updateItemDiscount(rowIndex, sto, discount, amountDiscount, sumHargaUpdate);
			}else if(update_for==UPDATE_SC){
				int scUpdate = (int) hm.get("scInt");
				updateItemSc(rowIndex, sto, scUpdate);
			}
			
		} catch (Exception e) {
			JOptionPane.showMessageDialog(null, "Data Update Product Null", "Error", JOptionPane.ERROR_MESSAGE);
		}
		
		updateRUAndTotalObat();
	}
	
	@Override
	public void insertDokter(HashMap<String, Object> hm) {
		try {
			Doctor doctor = (Doctor) hm.get("doctor");
			
			SalesTrx st = this.currentSalesTrx;
			st.setDoctor(doctor);
			
			SalesTrxDao dao = new SalesTrxDao();
			if(dao.saveOrUpdate(st)){
				this.currentSalesTrx = st;
				textFieldDokter.setText(doctor!=null? doctor.getFullName():"");
			}
			
		} catch (Exception e) {
			JOptionPane.showMessageDialog(null, "Inset Doctor: "+e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
		}
		
	}

	@Override
	public void insertCustomer(HashMap<String, Object> hm) {
		try {
			SalesTrx _st = (SalesTrx) hm.get("_st");
			Patients p = (Patients) hm.get("patient");
			
			String atasnama = "";
			String namapasien = "";
			if(p!=null){
				atasnama = p.getResponsiblePerson();
				namapasien = p.getPatientName();
			}
			
			textFieldCustNama.setText(namapasien);
			textFieldCustAtasNama.setText(atasnama);
			
			this.currentSalesTrx = _st;
			this.currentPatient = p;
		} catch (Exception e) {
			JOptionPane.showMessageDialog(null, "Insert Customer: "+e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
		}
	}
	
	@Override
	public void bayar(HashMap<String, Object> hm) {
		try {
			//SalesTrx st = (SalesTrx) hm.get("salesTrx");
			
			firstConditionForComp();
		} catch (Exception e) {
			JOptionPane.showMessageDialog(null, "Bayar: "+e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
		}
	}

	@Override
	public void focusGained(FocusEvent fe) {
		Object obj = fe.getSource();
		
		if(obj==textFieldBiayaDokter){
			String valStr = textFieldBiayaDokter.getText();
			if(valStr.trim().isEmpty()){
				valStr = "0";
			}
			
			String removeDot = AppUtil.removeCharacters(valStr, ".");
			textFieldBiayaDokter.setText(removeDot);
			
		}else if(obj==textFieldBiayaTindakan){
			String valStr = textFieldBiayaTindakan.getText();
			if(valStr.trim().isEmpty()){
				valStr = "0";
			}
			
			String removeDot = AppUtil.removeCharacters(valStr, ".");
			textFieldBiayaTindakan.setText(removeDot);
			
		}else if(obj==textFieldBiayaLab){
			String valStr = textFieldBiayaLab.getText();
			if(valStr.trim().isEmpty()){
				valStr = "0";
			}
			
			String removeDot = AppUtil.removeCharacters(valStr, ".");
			textFieldBiayaLab.setText(removeDot);
			
		}else if(obj==textFieldBiayaAdm){
			String valStr = textFieldBiayaAdm.getText();
			if(valStr.trim().isEmpty()){
				valStr = "0";
			}
			
			String removeDot = AppUtil.removeCharacters(valStr, ".");
			textFieldBiayaAdm.setText(removeDot);
			
		}else if(obj==textFieldMisc){
			String valStr = textFieldMisc.getText();
			if(valStr.trim().isEmpty()){
				valStr = "0";
			}
			
			String removeDot = AppUtil.removeCharacters(valStr, ".");
			textFieldMisc.setText(removeDot);
			
		}
	}
	
	@Override
	public void focusLost(FocusEvent fe) {
		Object obj = fe.getSource();
		
		if(obj==textFieldUpAsrPersen){
			updateUpAsr();
		}else if(obj==textFieldDiscountPersen){
			updateDiscount();
		}else if(obj==textFieldBiayaDokter){
			updateBiayaDokter();
		}else if(obj==textFieldBiayaTindakan){
			updateBiayaTindakan();
		}else if(obj==textFieldBiayaLab){
			updateBiayaLab();
		}else if(obj==textFieldBiayaAdm){
			updateBiayaAdm();	
		}else if(obj==textFieldMisc){
			updateMisc();
		}
	}

	@Override
	public void keyPressed(KeyEvent ke) {
		Object obj = ke.getSource();
		
		if(obj==textFieldUpAsrPersen){
			if(ke.getKeyCode()==KeyEvent.VK_ENTER){
				updateUpAsr();
				textFieldDiscountPersen.requestFocus();
			}
		}else if(obj==textFieldDiscountPersen){
			if(ke.getKeyCode()==KeyEvent.VK_ENTER){
				updateDiscount();
				textFieldBiayaDokter.requestFocus();
			}
		}else if(obj==textFieldBiayaDokter){
			if(ke.getKeyCode()==KeyEvent.VK_ENTER){
				updateBiayaDokter();
				textFieldBiayaTindakan.requestFocus();
			}
		}else if(obj==textFieldBiayaTindakan){
			if(ke.getKeyCode()==KeyEvent.VK_ENTER){
				updateBiayaTindakan();
				textFieldBiayaLab.requestFocus();
			}
		}else if(obj==textFieldBiayaLab){
			if(ke.getKeyCode()==KeyEvent.VK_ENTER){
				updateBiayaLab();
				textFieldBiayaAdm.requestFocus();
			}
		}else if(obj==textFieldBiayaAdm){
			if(ke.getKeyCode()==KeyEvent.VK_ENTER){
				updateBiayaAdm();
				textFieldMisc.requestFocus();
			}
		}else if(obj==textFieldMisc){
			if(ke.getKeyCode()==KeyEvent.VK_ENTER){
				updateMisc();
				btnBayar.requestFocus();
			}
		}else if(obj==btnTrxNew){
			if(ke.getKeyCode()==KeyEvent.VK_ENTER){
				btnTrxNewAction();
			}
		}else if(obj==btnBatal){
			if(ke.getKeyCode()==KeyEvent.VK_ENTER){
				btnBatalAction();
			}
		}else if(obj==btnBayar){
			if(ke.getKeyCode()==KeyEvent.VK_ENTER){
				btnBayarAction();
			}
		}else if(obj==btnAddProd){
			if(ke.getKeyCode()==KeyEvent.VK_ENTER){
				btnAddProdAction();
			}
		}else if(obj==btnEditQuantity){
			if(ke.getKeyCode()==KeyEvent.VK_ENTER){
				btnEditQuantityAction();
			}
		}else if(obj==btnEditDiscount){
			if(ke.getKeyCode()==KeyEvent.VK_ENTER){
				btnEditDiscountAction();
			}
		}else if(obj==btnEditSc){
			if(ke.getKeyCode()==KeyEvent.VK_ENTER){
				btnEditScAction();
			}
		}else if(obj==btnHapusProd){
			if(ke.getKeyCode()==KeyEvent.VK_ENTER){
				btnHapusProdAction();
			}
		}
		
	}

	@Override
	public void keyReleased(KeyEvent ke) {
		Object obj = ke.getSource();
		
		if(ke.getKeyCode()==KeyEvent.VK_0 || ke.getKeyCode()==KeyEvent.VK_1 || ke.getKeyCode()==KeyEvent.VK_2 || 
				ke.getKeyCode()==KeyEvent.VK_3 || ke.getKeyCode()==KeyEvent.VK_4 || ke.getKeyCode()==KeyEvent.VK_5 || 
				ke.getKeyCode()==KeyEvent.VK_6 || ke.getKeyCode()==KeyEvent.VK_7 || ke.getKeyCode()==KeyEvent.VK_8 || 
				ke.getKeyCode()==KeyEvent.VK_9 || ke.getKeyCode()==KeyEvent.VK_BACK_SPACE || ke.getKeyCode()==KeyEvent.VK_DELETE){
			
			if(obj==textFieldUpAsrPersen){
				String valStr = textFieldUpAsrPersen.getText();
				if(valStr.trim().isEmpty()){
					valStr = "0";
				}
				
				if(!AppUtil.isNumber(valStr)){
					JOptionPane.showMessageDialog(null, "Invalid.\nSilahkan masukkan angka", "Error", JOptionPane.ERROR_MESSAGE);
					return;
				}
				
				int valInt = Integer.parseInt(valStr);
				if(valInt<0 || valInt>100){
					JOptionPane.showMessageDialog(null, "Invalid.\nNilai Up Asurasi antara 0-100", "Error", JOptionPane.ERROR_MESSAGE);
					return;
				}
				
				String totalObatStr = textFieldTotalObat.getText();
				if(totalObatStr.trim().isEmpty()) totalObatStr = "0";
				String totalObat = AppUtil.removeCharacters(totalObatStr, ".");
				
				BigDecimal value = AppUtil.amountPersentasi(valInt, new BigDecimal(totalObat), 0);
				textFieldUpAsrRp.setText(AppUtil.formatStringIDR(value.intValue()));
				
			}else if(obj==textFieldDiscountPersen){
				String valStr = textFieldDiscountPersen.getText();
				if(valStr.trim().isEmpty()){
					valStr = "0";
				}
				
				if(!AppUtil.isNumber(valStr)){
					JOptionPane.showMessageDialog(null, "Invalid.\nSilahkan masukkan angka", "Error", JOptionPane.ERROR_MESSAGE);
					return;
				}
				
				int valInt = Integer.parseInt(valStr);
				if(valInt<0 || valInt>100){
					JOptionPane.showMessageDialog(null, "Discount Value invalid", "Error", JOptionPane.ERROR_MESSAGE);
					return;
				}
				
				String totalObatStr = textFieldTotalObat.getText();
				if(totalObatStr.trim().isEmpty()) totalObatStr = "0";
				String totalObat = AppUtil.removeCharacters(totalObatStr, ".");
				
				BigDecimal value = AppUtil.amountPersentasi(valInt, new BigDecimal(totalObat), 0);
				textFieldDiscountRp.setText(AppUtil.formatStringIDR(value.intValue()));
			
			}
		}
	}

	@Override
	public void keyTyped(KeyEvent ke) {
		// TODO Auto-generated method stub
	}

}
